<?php
			
	/* SVN FILE: $Id: preventiva.php 12 2011-03-14 13:34:57Z michele.andreoletti@gmail.com $ */
	
	/**
	 * Project Name : arcadia
	 *
	 * @author $Author: michele.andreoletti@gmail.com $
	 * @version $Revision: 12 $
	 * @lastrevision $Date: 2011-03-14 13:34:57 +0000 (Mon, 14 Mar 2011) $
	 * @filesource $URL: http://arcadia.googlecode.com/svn/trunk/global/preventiva.php $
	 */

	require_once 'include/functions.php';
	require_once 'include/const.inc.php';
	require_once '../include/auth.inc.php';
	require_once '../include/conn.inc.php';

	require_once('../include/view.php');

	if (!empty($iView)) {
	  	$sHeaderTitle = $sAPP_NAME." &raquo; ".$aData['sJob']." &raquo; ".$aData['sDescrizione'];
	  	$sTableTitle = "<div style='font-size: 0.7em'>Job: ".$aData['sJob']."</div><div>".$aData['sDescrizione']."</div>";
	} else  {
		$sHeaderTitle = $sAPP_NAME." &raquo; $sTableTitle";
	}
	
	$html .= "<div id='tabs'><ul>$sTabsHtml</ul>";
	
	$i = 1;
	if (is_allowed('view', fnFieldAccessLvl($iAccessLvl, $i))) {
		
		$html .= "<div id='tabs-$i'>";
			
			$html .= ($sAction == 'edit' ? "<form method='post' id='form-tab-$i' class='buttons' action='transact.php'>" : '');		
			$html .= "<table class='standard' border='".fnTableBorder()."' width='98%'>";
				
				$html .= "<col width='25%'><col width='25%'><col width='25%'><col width='25%'>";
				$html .= "<tbody>";
				
				$html .= "<tr><td>".fnTextInput('sJob','Job Asset+',$aData, 12)."</td><td>".fnSelectInput('iJobType','Campo Interv.',$aData, fnSelOptionsFromResources('JOBTYPE'),'index')."</td><td colspan='2'>".fnSelectInput('iJobStatus','Stato Interv.',$aData, fnSelOptionsFromResources('JOBSTATUS'),'index')."</td></tr>";
				$html .= "<tr><td>".fnSelectInput('iCriticita','Criticità App.',$aData, fnSelOptionsFromResources('CRITICITA'),'index')."</td><td colspan='2'>".fnTextInput('sDescrizione','Descrizione',$aData, 45)."</td><td>&nbsp;</td></tr>";
				$html .= "<tr><td>".fnSelectInput('iJobDuty','Responsabilità Attività',$aData, fnSelOptionsFromResources('JOBDUTY'),'index')."</td><td colspan='3'>&nbsp;</td></tr>";
																			
				$html .= "<tr><td>".fnTextInput('dtVerifica','Data Verifica',$aData, 30)."</td><td colspan='2'>".fnSelectInput('iReferente', 'Referente Verifica', $aData, fnSelOptionsFromResources('SIC', '1', 'iReferente'), 'index')."</td><td>&nbsp;</td></tr>";
				
				$html .= "<tr><td colspan='3' class='top-line'>".fnTextInput('sGiorniRitardo', 'Giorni di ritardo rispetto alla pianificazione (valore negativo se in anticipo)',$aData, 6)."</td><td class='top-line'>".($sAction == 'edit' ? "<span id='date-difference-calculator-opener' class='pointer'><img alt='Calcolo differenza tra due date' title='Calcolo differenza tra due date' src='./images/calculator.png'></span>" : "&nbsp;")."</td></tr>";
				
				if (empty($iView) || (!empty($iView) && $sAction!='edit' && (!empty($aData['iErroriScheda']) || !empty($aData['sErroriScheda']))) || (!empty($iView) && $sAction=='edit'))	
					$html .= "<tr><td class='top-line'>".fnCheckboxInput('iErroriScheda','Errori Scheda Global Service',$aData)."</td><td colspan='3' class='top-line'>".fnTextareaInput('sErroriScheda','Errori Scheda Global Service',$aData)."</td></tr>";
				if (empty($iView) || (!empty($iView) && $sAction!='edit' && (!empty($aData['iErroriAsset']) || !empty($aData['sErroriAsset']))) || (!empty($iView) && $sAction=='edit'))	
					$html .= "<tr><td class='top-line'>".fnCheckboxInput('iErroriAsset','Errori Asset+',$aData)."</td><td colspan='3' class='top-line'>".fnTextareaInput('sErroriAsset','Errori Asset+',$aData)."</td></tr>";
				if (empty($iView) || (!empty($iView) && $sAction!='edit' && (!empty($aData['iFrequenzaSolleciti']) || !empty($aData['sFrequenzaSolleciti']))) || (!empty($iView) && $sAction=='edit'))	
					$html .= "<tr><td class='top-line'>".fnCheckboxInput('iFrequenzaSolleciti','Frequenza Solleciti inadeguata (superiore a 7 giorni)',$aData)."</td><td colspan='3' class='top-line'>".fnTextareaInput('sFrequenzaSolleciti','Frequenza Solleciti inadeguata (superiore a 7 giorni)',$aData)."</td></tr>";
				
				if (empty($iView) || (!empty($iView) && $sAction!='edit' && !empty($aData['sNote'])) || (!empty($iView) && $sAction=='edit'))			
					$html .= "<tr><td colspan='3' class='top-line'>".fnTextareaInput('sNote','Note',$aData)."</td><td class='top-line'>&nbsp;</td></tr>";
			
				$html .= "</tbody>";
			$html .= "</table>";
			
			if ($iView != 0) { 
				$html .= "<h5>".fnHtmlLastModify($aData['tsLastModify'])."</h5>";
			} else { 
				$html .= "<h5>&nbsp;</h5>";	
			}
			$html .= fnButtons($iView, $i, $iAccessLvl, $aData);
			
		$html .= "	</div>";		
	}
	
	$i = $iTabUploads;
	if (is_allowed('view', fnFieldAccessLvl($iAccessLvl, $sViewItemLink, $i))) { 
		
		$html .= "<div id='tabs-$i'>";			
			$html .= fnUploadsTabContent($iView, $sViewItemLink, $i);
		$html .= "</div>";
	
	}
	
	$html .= "</div>";	
	
	$html .= "<div id='date-difference-calculator' title='Calcolo differenza tra due date'>";
		$html .= "	Data 1: <input type='text' size='12' name='date-difference-calculator-t1' id='date-difference-calculator-t1'><br/>";
		$html .= "	Data 2: <input type='text' size='12' name='date-difference-calculator-t2' id='date-difference-calculator-t2'><br/>";
		$html .= "	Giorni: <input type='text' size='6' name='date-difference-calculator-days' id='date-difference-calculator-days'><br/>";
	$html .= "</div>";
	
	// contenuto <head> della pagine
	$sHeadContent .= fnViewHeadContent($iTab, $aDisabledTabs);
	
	$bSEARCH_FORM_SHOW = false; // il form di ricerca non viene visualizzato nello script $sViewItemLink
								// non posso assegnare subito questo valore a $bSEARCH_FORM_SHOW perchè
								// alcune funzioni in ../include/view.php utilizzano questa variabile.
								
	require_once('../themes/'.$sTHEME.'/template.php');
	die();




	function fnViewHeadContent ($iTab, $aTabsDisabled) {

		global $sSUITE_NAME, $sAPP;
		
		global $iView, $sViewItemLink;
		
		global $sAction;
		
		global $sJsDocumentReady;
		
		global $aTabsLabels;
		
		$sTabsDisabled = '';
		foreach ($aTabsDisabled as $i) { $sTabsDisabled .= "$i, "; }
		$sTabsDisabled = ($sTabsDisabled!='' ? " disabled: [".substr_replace( $sTabsDisabled, "", -2 )."] " : '');

		$iTabSelected = $i = 0;
		foreach ($aTabsLabels as $sKey => $sValue) {
			if ($sKey == $iTab) { $iTabSelected = $i; }
			$i++;
		}
		
		$sSelectedTab = ($iTabSelected!=0 && !in_array($iTabSelected, $aTabsDisabled) ? ($sTabsDisabled!="" ? ", " : '') . " selected: $iTabSelected " : "");

		$sHeadContent = "
		
			<script type='text/javascript' charset='utf-8'>
	
				$().ready(function() {
					
					var oClicked = null;
					
					$sJsDocumentReady
					
					$('#tabs').tabs({ $sTabsDisabled $sSelectedTab });
				
					$('button, input:submit', '.buttons').button();
					
					$('.ui-toggable').click(function() {
						fnToggle($(this));

					});
					
					function fnToggle (oObj) {
						src = oObj.attr('src'),
							onCheck = /\_on\.png$/,
							offCheck = /\_off\.png$/;
						$.getJSON('../include/toggle.php', {'sAction': 'toggle',
															'sField': oObj.attr('sField'),
															'sValue': (src.match(onCheck) ? 0 : 1),
															'iView': '$iView',
															'sTable': '',
															'sViewItemLink': '$sViewItemLink',
															'sAPP': '$sAPP'	}, function (json) {
							if (json[0].sAction=='toggle' && json[0].sError=='') { 
								if(src.match(onCheck)) {
									oObj.attr('src', src.replace(onCheck, '_off.png'));
								} else if (src.match(offCheck)) {
									oObj.attr('src', src.replace(offCheck, '_on.png'));
								}
							} else { 
								alert ('Error: ' + json[0].sError);
							} 		
						})
					};
					
					$('#date-difference-calculator').dialog( {
						autoOpen: false,
						resizable: false,
						modal: false,
						buttons: {
							Chiudi: function() {
								$(this).dialog('close');
							}
						}
					}); " . ($sAction == 'view' ? "
					
					$('textarea.mceViewer').tinymce({
						// Location of TinyMCE script
						script_url : '../include/tiny_mce/tiny_mce.js',
						// General options
						theme : 'advanced',
						readonly : true
			
					}); " : "
					
					$('#date-difference-calculator-opener').click(function() {
						$('#date-difference-calculator').dialog('open');
						return false;
					});
					
					$('#date-difference-calculator-t1, #date-difference-calculator-t2').datepicker({
						showOn: 'button',
						buttonImage: './images/calendar.gif',
						buttonImageOnly: true,
						onSelect: function(dateText, inst) {
							$(this).change();
						}
					});
					
					$('#date-difference-calculator-t1, #date-difference-calculator-t2').change(function() {
						var one_day=1000*60*60*24; 
						var t1=$('#date-difference-calculator-t1').val().split('/');     
						var t2=$('#date-difference-calculator-t2').val().split('/');
						var date1=new Date(t1[2],(t1[1]-1),t1[0]);
						var date2=new Date(t2[2],(t2[1]-1),t2[0]);
						var month1=t1[1]-1;
						var month2=t2[1]-1;
						days=Math.ceil((date2.getTime()-date1.getTime())/(one_day)); 
						if (!isNaN(days)) {
							$('#date-difference-calculator-days').val(-days);
						 }
					});
					
					$('textarea.mceEditor').tinymce({
						// Location of TinyMCE script
						script_url : '../include/tiny_mce/tiny_mce.js',
						// General options
						theme : 'advanced',
						// Theme options
						theme_advanced_buttons1 : 'bold,italic,underline,strikethrough,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,bullist,numlist,separator,undo,redo,separator,cleanup,separator,forecolor,backcolor,separator,charmap',
						theme_advanced_buttons2 : '', theme_advanced_buttons3 : '', theme_advanced_buttons4 : '',
						theme_advanced_toolbar_location : 'top',
						theme_advanced_toolbar_align : 'left',
						theme_advanced_resizing : false
			
					}); ") . "
		    
				});
				
				</script> ";
	
		return $sHeadContent;
	}